var a = require("../../@babel/runtime/helpers/interopRequireDefault"), e = require("../../@babel/runtime/helpers/defineProperty"), t = a(require("../../utils/util.js")), i = getApp();

Page({
    data: {
        code: "",
        info: {},
        avatar_image: "",
        nickname: "",
        _nickname: "",
        fileList: [],
        change_hidden: !0,
        info_form: {
            realname: "",
            telephone: "",
            mobile: "",
            wx: "",
            alipay: "",
            birthday: "",
            alipay_name: "",
            gender: "",
            avatar: "",
            province_name: "",
            city_name: "",
            area_name: "",
            province: "",
            city: "",
            area: "",
            address: "",
            nickname: ""
        },
        sexName: "",
        isShowSex: !1,
        isShowAddress: !1,
        districtName: "",
        isShowBirthday: !1,
        bind_btn: "",
        is_custom: !1,
        custom_title: "",
        custom_value: "",
        isForm: !1,
        customDatas: [],
        isBalancePwd: !1,
        showSex: !1,
        sexItems: [ {
            name: "男"
        }, {
            name: "女"
        } ],
        birthdayShow: !1,
        minDate: new Date(1900, 1, 1).getTime(),
        maxDate: new Date().getTime(),
        currentDate: new Date().getTime(),
        currentDate_1: new Date().getTime(),
        date: t.default.formatTime(new Date()).substring(0, 10),
        showAdd: !1,
        provinceData: [],
        cityData: [],
        districtData: [],
        pickerValue: [ 0, 0, 0 ],
        selectAddressData: [],
        is_open_converge_pay: !1,
        formOpen: !1,
        formEdit: !1,
        memberCancel: !1,
        lofgin_show: !1,
        change_info: !1
    },
    bindDateChange: function(a) {
        console.log(a.detail.value), this.setData({
            "info_form.birthday": a.detail.value
        });
    },
    deletePhoto: function() {
        this.setData({
            fileList: []
        });
    },
    afterRead: function(a) {
        var e = this, t = a.detail.file, s = i.getNetAddresss("upload.uploadPic");
        wx.uploadFile({
            url: s,
            filePath: t.url,
            name: "file",
            formData: null,
            success: function(a) {
                console.log(JSON.parse(a.data));
                var t = JSON.parse(a.data);
                e.setData({
                    fileList: [ {
                        url: t.data.img_url
                    } ],
                    "info_form.avatar": t.data.img_url
                });
            }
        });
    },
    onLoad: function(a) {},
    onReady: function() {},
    onShow: function() {
        this._init(), this._initAddressInfo(), this._getMemberInfo();
    },
    onHide: function() {
        this.setData({
            change_hidden: !1
        });
    },
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    getUserProfileTap: function() {
        var a = this;
        wx.getUserProfile({
            desc: "获取用户信息",
            success: function(e) {
                console.log("info:", e);
                var t = {
                    nickName: e.userInfo.nickName,
                    avatarUrl: e.userInfo.avatarUrl,
                    gender: e.userInfo.gender
                };
                a.setData({
                    info: t
                }), a.updateInfo();
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    updateInfo: function() {
        var a = this, e = i.getNetAddresss("member.member-update.index");
        i._postNetWork({
            url: e,
            data: {
                type: 2,
                info: a.data.info
            },
            success: function(e) {
                var t = e.data;
                1 == t.result ? (wx.showToast({
                    icon: "none",
                    title: t.msg,
                    duration: 1e3
                }), a._getMemberInfo()) : wx.showToast({
                    icon: "none",
                    title: t.msg,
                    duration: 1e3
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    _getMemberInfo: function() {
        var a = this, e = i.getNetAddresss("member.member.getUserInfo");
        i._getNetWork({
            url: e,
            success: function(e) {
                var t = e.data;
                if (1 == t.result) {
                    var i = !1, s = !1, n = !1, o = !1;
                    a.data.change_hidden && a.setData({
                        fileList: [ {
                            url: t.data.avatar_image,
                            isImage: !0
                        } ],
                        _nickname: t.data.nickname
                    }), a.setData({
                        nickname: t.data.nickname,
                        change_info: t.data.change_info
                    }), i = 1 == t.data.is_open_converge_pay, t.data.myform && t.data.myform.base && (s = "1" == t.data.myform.base.form_open, 
                    n = "1" == t.data.myform.base.form_edit, o = "1" == t.data.myform.base.name), t.data.name_must && a.setData({
                        name_must: "1" == t.data.name_must
                    }), a.setData({
                        is_open_converge_pay: i,
                        formOpen: s,
                        formEdit: n,
                        formName: o,
                        lofgin_show: !0
                    }), a._initData(t.data);
                } else wx.showToast({
                    icon: "none",
                    title: t.msg,
                    duration: 1e3
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    _initData: function(a) {
        this.setData({
            avatar_image: a.avatar_image
        }), this.setData({
            nickname: a.nickname
        }), this._initSex(a), this.setData({
            "info_form.wx": a.wechat
        }), this.setData({
            "info_form.realname": a.realname
        }), this._initAliPay(a), this._initDistrict(a, ""), this.setData({
            "info_form.avatar": a.avatar,
            memberCancel: a.member_cancel_status
        }), this._initBirthday(a), this._initMobile(a), this._initCustomData(a), this._initCustomForm(a), 
        this._getBalancePawInfo();
    },
    _initSex: function(a) {
        a.myform.base && this.setData({
            isShowSex: 1 == a.myform.base.sex
        }), 1 == a.gender ? this.setData({
            "info_form.gender": "1",
            sexName: "男"
        }) : 2 == a.gender ? this.setData({
            "info_form.gender": "2",
            sexName: "女"
        }) : this.setData({
            "info_form.gender": "0",
            sexName: "未定义"
        });
    },
    _initAliPay: function(a) {
        this.setData({
            "info_form.alipay": a.alipay,
            "info_form.alipay_name": a.alipay_name
        });
    },
    _initDistrict: function(a, e) {
        if (console.log(i._isTextEmpty(a.myform)), !i._isTextEmpty(a)) return i._isTextEmpty(a.myform.form) || this.setData({
            isShowAddress: 1 == a.myform.base.address
        }), void this.setData({
            "info_form.province": a.province,
            "info_form.province_name": a.province_name,
            "info_form.city": a.city,
            "info_form.city_name": a.city_name,
            "info_form.area": a.area,
            "info_form.area_name": a.area_name,
            districtName: a.province_name + " " + a.city_name + " " + a.area_name,
            "info_form.address": a.address
        });
        i._isTextEmpty(e) || (this.setData({
            "info_form.province": e.itemValue1,
            "info_form.province_name": e.itemName1,
            "info_form.city": e.itemValue2,
            "info_form.city_name": e.itemName2,
            "info_form.area": e.itemValue3,
            "info_form.area_name": e.itemName3
        }), this.setData({
            districtName: e.itemName1 + " " + e.itemName2 + " " + e.itemName3
        }));
    },
    _initBirthday: function(a) {
        a.myform.base && this.setData({
            isShowBirthday: 1 == a.myform.base.birthday
        });
        var e = new Date(a.birthday).getTime();
        this.setData({
            "info_form.birthday": a.birthday,
            currentDate: e
        });
    },
    _initMobile: function(a) {
        this.setData({
            "info_form.mobile": a.mobile
        }), i._isTextEmpty(this.data.info_form.mobile) ? this.setData({
            bind_btn: "绑定手机"
        }) : this.setData({
            bind_btn: "修改手机"
        });
    },
    _initCustomData: function(a) {
        i._isTextEmpty(a.yz_member) || (this.setData({
            custom_value: a.yz_member.custom_value
        }), this._getMemberInfo2(this.data.custom_value));
    },
    _getMemberInfo2: function(a) {
        var e = this, t = i.getNetAddresss("member.member.get-custom-field");
        i._getNetWork({
            url: t,
            success: function(a) {
                var t = a.data;
                1 == t.result && e.setData({
                    is_custom: "1" == t.data.is_custom,
                    custom_title: t.data.custom_title
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    _initCustomForm: function(a) {
        i._isTextEmpty(a.myform) || i._isTextEmpty(a.myform.form) ? this.setData({
            isForm: !1
        }) : 0 != a.myform.form.length ? (this.setData({
            isForm: !0
        }), this.setData({
            customDatas: a.myform.form
        })) : this.setData({
            isForm: !1
        });
    },
    _getBalancePawInfo: function() {
        var a = this, e = i.getNetAddresss("member.balance-password.is-use");
        i._getNetWork({
            url: e,
            success: function(e) {
                var t = e.data;
                1 == t.result && a.setData({
                    isBalancePwd: t.data.is_use
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    nicknameChange: function(a) {
        this.setData({
            _nickname: a.detail.value
        });
    },
    realnameinp: function(a) {
        var e = a.detail.value;
        this.setData({
            "info_form.realname": e
        });
    },
    bindTel: function() {
        wx.navigateTo({
            url: "/packageA/member/editmobile/editmobile?num=" + this.data.info_form.mobile + "&fromApp=2&editType=1"
        }), wx.setStorage({
            key: "isset",
            data: 1
        });
    },
    showSexInfo: function() {
        this.setData({
            showSex: !0
        });
    },
    sexSelectBtn: function(a) {
        var e = a.detail.name;
        console.log(e), "男" == e ? this.setData({
            "info_form.gender": "1",
            sexName: "男"
        }) : "女" == e && this.setData({
            "info_form.gender": "2",
            sexName: "女"
        }), this.setData({
            showSex: !1
        });
    },
    sexClose: function() {
        this.setData({
            showSex: !1
        });
    },
    openPicker: function() {
        this.setData({
            birthdayShow: !0
        });
    },
    birthdayClose: function() {
        this.setData({
            birthdayShow: !1
        });
    },
    birthdayChange: function(a) {
        var e = a.detail;
        this.setData({
            currentDate: e
        });
    },
    timestampToTime: function(a) {
        var e = new Date(a);
        return e.getFullYear() + "-" + ((e.getMonth() + 1 < 10 ? "0" + (e.getMonth() + 1) : e.getMonth() + 1) + "-") + e.getDate();
    },
    wxinp: function(a) {
        var e = a.detail.value;
        this.setData({
            "info_form.wx": e
        });
    },
    alipayinp: function(a) {
        var e = a.detail.value;
        this.setData({
            "info_form.alipay": e
        });
    },
    alipayNameinp: function(a) {
        var e = a.detail.value;
        this.setData({
            "info_form.alipay_name": e
        });
    },
    showAddBtn: function() {
        this.setData({
            showAdd: !0
        });
    },
    _closeDateLw: function() {
        this.setData({
            showAdd: !1
        });
    },
    _initAddressInfo: function() {
        var a = this;
        wx.getStorage({
            key: "provinceData",
            success: function(e) {
                console.log("地址信息准备就绪"), a._getProvinceData();
            },
            fail: function(e) {
                console.log("省fail"), i._getNetWork({
                    url: i.getNetAddresss("member.member-address.address"),
                    success: function(e) {
                        var t = e.data, i = t.data.province, s = t.data.city, n = t.data.district;
                        wx.setStorage({
                            key: "provinceData",
                            data: i
                        }), wx.setStorage({
                            key: "cityData",
                            data: s
                        }), wx.setStorage({
                            key: "districtData",
                            data: n
                        }), a._initAddressInfo();
                    },
                    fail: function(a) {},
                    state: !0
                });
            }
        });
    },
    _getProvinceData: function() {
        var a = this;
        wx.getStorage({
            key: "provinceData",
            success: function(e) {
                console.log("省读取成功", e.data), a.setData({
                    provinceData: e.data
                }), a.setData({
                    "selectAddressData[0].name": e.data[a.data.pickerValue[0]].areaname,
                    "selectAddressData[0].id": e.data[a.data.pickerValue[0]].id,
                    "selectAddressData[0].index": a.data.pickerValue[0]
                }), a._getCityData();
            }
        });
    },
    _getCityData: function() {
        var a = this.data.selectAddressData[0];
        console.log("城市", "_data", a);
        var e = this;
        wx.getStorage({
            key: "cityData",
            success: function(t) {
                console.log("城市读取成功", t);
                for (var i = [], s = 0; s < t.data.length; s++) t.data[s].parentid == a.id && i.push(t.data[s]);
                console.log("城市数据筛选", i), e.setData({
                    cityData: i
                }), e.setData({
                    "selectAddressData[1].name": i[e.data.pickerValue[1]].areaname,
                    "selectAddressData[1].id": i[e.data.pickerValue[1]].id,
                    "selectAddressData[1].index": e.data.pickerValue[1]
                }), e._getDistrictData();
            }
        });
    },
    _getDistrictData: function() {
        var a = this.data.selectAddressData[1];
        console.log("地区", "_data", a), console.log(a);
        var e = this;
        wx.getStorage({
            key: "districtData",
            success: function(t) {
                console.log("地区读取成功");
                for (var i = [], s = 0; s < t.data.length; s++) t.data[s].parentid == a.id && i.push(t.data[s]);
                console.log("地区数据筛选", i), e.setData({
                    districtData: i
                }), console.log("districtData", i), e.setData({
                    "selectAddressData[2].name": i[e.data.pickerValue[2]].areaname,
                    "selectAddressData[2].id": i[e.data.pickerValue[2]].id,
                    "selectAddressData[2].index": e.data.pickerValue[2]
                }), console.log("over", e.data.selectAddressData);
            }
        });
    },
    bindChange: function(a) {
        var e = a.detail.value;
        this.data.pickerValue[0] != e[0] && (e[1] = 0, e[2] = 0), this.data.pickerValue[1] != e[1] && (e[2] = 0), 
        this.setData({
            "pickerValue[0]": e[0],
            "pickerValue[1]": e[1],
            "pickerValue[2]": e[2]
        }), this._initAddressInfo();
    },
    resultAdd: function() {
        var a = this.data.selectAddressData, e = {
            itemValue1: a[0].id,
            itemName1: a[0].name,
            itemValue2: a[1].id,
            itemName2: a[1].name,
            itemValue3: a[2].id,
            itemName3: a[2].name
        };
        this._initDistrict("", e), this._closeDateLw();
    },
    addressinp: function(a) {
        var e = a.detail.value;
        this.setData({
            "info_form.address": e
        });
    },
    cItemInp: function(a) {
        var t = a.currentTarget.dataset.citemidx, i = a.detail.value;
        console.log(this.data.customDatas), this.setData(e({}, "customDatas[" + t + "].value", i));
    },
    editBank: function() {
        wx.navigateTo({
            url: "/packageA/member/memberBank/memberBank"
        });
    },
    editBalancePwd: function() {
        var a = i.getNetAddresss("member.balance-password.is-has-password");
        i._getNetWork({
            url: a,
            success: function(a) {
                var e = a.data;
                1 == e.result ? e.data.is_has ? wx.navigateTo({
                    url: "/packageA/member/balance_password/balance_password"
                }) : wx.navigateTo({
                    url: "/packageA/member/set_balance_password/set_balance_password"
                }) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1e3
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    editCustom: function() {
        i._isTextEmpty(this.data.custom_value) && wx.navigateTo({
            url: "/packageA/member/info_costom/info_costom"
        });
    },
    editUSer: function() {
        wx.navigateTo({
            url: "/packageA/others/HJinfo/bankCardInformation/bankCardInformation"
        });
    },
    submitInfo: function() {
        if ((this.setData({
            "info_form.customDatas": this.data.customDatas,
            "info_form.avatar": this.data.fileList[0].url,
            "info_form.nickname": this.data._nickname
        }), this.data.formOpen && this.data.customDatas instanceof Array) && !this.data.customDatas.every(function(a) {
            return "" != a.value;
        })) return void wx.showToast({
            title: "请先填写自定义信息",
            icon: "none"
        });
        var a = i.getNetAddresss("member.member.updateUserInfo");
        i._postNetWork({
            url: a,
            showToastIn: !1,
            data: {
                data: this.data.info_form
            },
            success: function(a) {
                var e = a.data;
                1 == e.result ? wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1500,
                    success: function() {
                        setTimeout(function() {
                            wx.navigateBack({
                                delta: 1
                            });
                        }, 1500);
                    }
                }) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(a) {}
        });
    },
    _init: function() {
        this.setData({
            info_form: {
                realname: "",
                telephone: "",
                mobile: "",
                wx: "",
                alipay: "",
                birthday: "",
                alipay_name: "",
                gender: "",
                avatar: "",
                province_name: "",
                city_name: "",
                area_name: "",
                province: "",
                city: "",
                area: "",
                address: ""
            },
            sexName: "",
            isShowSex: !1,
            isShowAddress: !1,
            districtName: "",
            isShowBirthday: !1,
            bind_btn: "",
            is_custom: !1,
            custom_title: "",
            custom_value: "",
            isForm: !1,
            customDatas: [],
            isBalancePwd: !1,
            showSex: !1,
            sexItems: [ {
                name: "男"
            }, {
                name: "女"
            } ],
            birthdayShow: !1,
            minDate: new Date(1900, 1, 1).getTime(),
            maxDate: new Date().getTime(),
            currentDate: new Date().getTime(),
            showAdd: !1,
            provinceData: [],
            cityData: [],
            districtData: [],
            pickerValue: [ 0, 0, 0 ],
            selectAddressData: []
        });
    },
    goMemberCancel: function() {
        wx.navigateTo({
            url: "/packageI/member_cancel/member_cancel"
        });
    }
});